package com.yunysha.struts.action;

import java.io.PrintWriter;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.yunysha.constants.YunyshaConstants;
import com.yunysha.struts.actionform.CompanyMasterForm;
import com.yunysha.controller.YunyshaController;

public class CompanyMasterAction extends Action{
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
	String subAction=request.getParameter("subAction")==null?"":request.getParameter("subAction").toString();	
	if(subAction.equalsIgnoreCase("save"))
	{
		
		System.out.println("in save");
		HashMap<String,String> dataMap=new HashMap<String,String>();
		String txtCode=request.getParameter("txtCode")==null?"":request.getParameter("txtCode").toString();
		dataMap.put("txtCode", txtCode);
		String txtCompanyName=request.getParameter("txtCompanyName")==null?"":request.getParameter("txtCompanyName").toString();
		dataMap.put("txtCompanyName", txtCompanyName);
		String txtCustHandledBy=request.getParameter("txtCustHandledBy")==null?"":request.getParameter("txtCustHandledBy").toString();
		dataMap.put("txtCustHandledBy", txtCustHandledBy);
		String txtCAddress=request.getParameter("txtCAddress")==null?"":request.getParameter("txtCAddress").toString();
		dataMap.put("txtCAddress", txtCAddress);
		String txtCCategory=request.getParameter("txtCCategory")==null?"":request.getParameter("txtCCategory").toString();
		dataMap.put("txtCCategory", txtCCategory);
		String txtCStatus=request.getParameter("txtCStatus")==null?"":request.getParameter("txtCStatus").toString();
		dataMap.put("txtCStatus", txtCStatus);
		String txtCState=request.getParameter("txtCState")==null?"":request.getParameter("txtCState").toString();
		dataMap.put("txtCState", txtCState);
		String txtCCity=request.getParameter("txtCCity")==null?"":request.getParameter("txtCCity").toString();
		dataMap.put("txtCCity", txtCCity);
		String txtCZone=request.getParameter("txtCZone")==null?"":request.getParameter("txtCZone").toString();
		dataMap.put("txtCZone", txtCZone);
		String txtRemarks=request.getParameter("txtRemarks")==null?"":request.getParameter("txtRemarks").toString();
		dataMap.put("txtRemarks", txtRemarks);
		String txtCShippingAddress=request.getParameter("txtCShippingAddress")==null?"":request.getParameter("txtCShippingAddress").toString();
		dataMap.put("txtCShippingAddress", txtCShippingAddress);
		String txtCBillingAddress=request.getParameter("txtCBillingAddress")==null?"":request.getParameter("txtCBillingAddress").toString();
		dataMap.put("txtCBillingAddress", txtCBillingAddress);
		String txtCPanNo=request.getParameter("txtCPanNo")==null?"":request.getParameter("txtCPanNo").toString();
		dataMap.put("txtCPanNo", txtCPanNo);
		String txtCVatTinNo1=request.getParameter("txtCVatTinNo1")==null?"":request.getParameter("txtCVatTinNo1").toString();
		dataMap.put("txtCVatTinNo1", txtCVatTinNo1);
		String txtCVatTinNo2=request.getParameter("txtCVatTinNo2")==null?"":request.getParameter("txtCVatTinNo2").toString();
		dataMap.put("txtCVatTinNo2", txtCVatTinNo2);
		String txtCPaymentTerms=request.getParameter("txtCPaymentTerms")==null?"":request.getParameter("txtCPaymentTerms").toString();
		dataMap.put("txtCPaymentTerms", txtCPaymentTerms);
		String txtCCreditLimit=request.getParameter("txtCCreditLimit")==null?"":request.getParameter("txtCCreditLimit").toString();
		dataMap.put("txtCCreditLimit", txtCCreditLimit);
		String txtCCategoryAmt1=request.getParameter("txtCCategoryAmt1")==null?"":request.getParameter("txtCCategoryAmt1").toString();
		dataMap.put("txtCCategoryAmt1", txtCCategoryAmt1);
		String txtCCategoryAmt2=request.getParameter("txtCCategoryAmt2")==null?"":request.getParameter("txtCCategoryAmt2").toString();
		dataMap.put("txtCCategoryAmt2", txtCCategoryAmt2);
		String txtCCategoryAmt3=request.getParameter("txtCCategoryAmt3")==null?"":request.getParameter("txtCCategoryAmt3").toString();
		dataMap.put("txtCCategoryAmt3", txtCCategoryAmt3);
		String txtDiscount=request.getParameter("txtDiscount")==null?"":request.getParameter("txtDiscount").toString();
		dataMap.put("txtDiscount", txtDiscount);
		String contactCount=request.getParameter("contactCount")==null?"":request.getParameter("contactCount").toString();
		dataMap.put("contactCount", contactCount);
		String diamondCount=request.getParameter("diamondCount")==null?"":request.getParameter("diamondCount").toString();
		dataMap.put("diamondCount", diamondCount);
		
		YunyshaController yc=new YunyshaController();
		System.out.println("about to call controller");
		yc.saveCompanyMaster(dataMap);
		
	}
		
	
	
	String forward = null;
	CompanyMasterForm cForm = (CompanyMasterForm) form;
	forward = YunyshaConstants.SUCCESS;
	
	return mapping.findForward(forward);
	}
}
